package com.immunology.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.immunology.model.MappingPages;
import com.immunology.service.ComplaintService;

public class AddComplaintServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public AddComplaintServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		getServletContext()
				.getRequestDispatcher(MappingPages.ADD_COMPLAINT_JSP).forward(
						request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String complaintName = request.getParameter("complaint");
		int complaintTypeId = Integer.parseInt(request
				.getParameter("complaintType"));

		ComplaintService complaintService = ComplaintService.getInstance();
		complaintService.insert(complaintName, complaintTypeId);
		
		getServletContext()
				.getRequestDispatcher(MappingPages.ADD_COMPLAINT_JSP).forward(
						request, response);
	}

}
